<?php
/**
 * gpa_demo Description
 * @package 
 * @name register
 * @filesource register.php
 * @author Meta Sanjaya
 */

$post =& $_POST;
$session =& $_SESSION;

if(isset($post['submit']) && isset($session['token']) && $post['token']==$session['token'] && !empty($post['userid'])) {
    unset($session['token']);

    $db->query("INSERT INTO #_users SET `group_id`='%u', `username`='%s', `pwd`='%s', `display_email`='%u'", $CONFIG['default_group'], escape($post['userid']), pwd_gen($post['passwd1'], $post['userid']), $post['displayemail']);
    $uid = $db->getIsertId();
    $db->query("INSERT INTO #_users_profile SET `user_id`='%u', `name`='%s', `email`='%s', `url`='%s', `city`='%s', `province`='%s', `country`='%s', `information`='%s'",
            $uid, escape($post['name']), escape($post['email']), escape($post['url']), escape($post['kota']), escape(!empty($post['propinsi']) ? $post['propinsi'] : $post['propinsiln']), escape($post['negara']), escape($post['keterangan']));
    if($CONFIG['email_validation']) {
        $html = '<p>terima kasih telah mendaftar di '.$CONFIG['site_name'].'.<br />ini adalah email validasi untuk user: "'.$post['user_id'].'"</p>';
        $html .= '<p>klik link ini untuk validasi</p>';
        $html .= '<a href="'.HTTP_SERVER .'?page=user&amp;act=e-valid&amp;username='.$post['userid'].'&amp;token='.$post['token'].'">'.HTTP_SERVER .'?page=user&amp;act=e-valid&amp;username='.$post['userid'].'&amp;token='.$post['token'].'</a>';

        $db->query("INSERT INTO #_users_validation SET user_id='$uid', token='".$post['token']."'");

        Mail::sendHtml($post['email'], $CONFIG['admin_email'], $CONFIG['site_name'] . " - User Registration Email Validation", $html);

        header('location: '.HTTP_SERVER.'?page=user&act=email-validation.html');
    } else {
        $db->query("UPDATE #_users SET active='1' WHERE user_id='$uid'");

        Mail::sendText($post['email'], $CONFIG['admin_email'], $CONFIG['site_name'] . " - Thank You For Your Registration", "Thank You for registering in ".$CONFIG['site_name'].". Enjoy!");

        header('location: '.HTTP_SERVER.'?page=user&act=register-success.html');
    }
} else {
    $session['token'] = md5(microtime(true));
    include_once 'register.html.php';
}

?>
